package gdr.graphics;

import gdr.map.*;
import gdr.player.*;
import java.awt.*;

/**
 * Interfaccia grafica per il giocatore
 * @author Giorgio Vitale
 *
 */
public class PlayerGraphics  implements RendablePlayer{
	/**
	 * Posizione in cui si trova il personaggio
	 */
	protected BattleMapUnit mapUnit;
	protected Color color;
	protected CoordinateCalculator coordinateCalc;
	protected DefaultPlayer player;
	
	public void update(long elapsedTime){
		
	}
	
	public void render(Graphics2D g){
		g.setColor(color);
		int b = 5;
		g.fillOval(coordinateCalc.getX(mapUnit.getPos()) + coordinateCalc.resize(b), 
				   coordinateCalc.getY(mapUnit.getPos()) + coordinateCalc.resize(b), 
				   coordinateCalc.resize(CoordinateCalculator.UNIT_WIDTH) - coordinateCalc.resize(2*b), 
				   coordinateCalc.resize(CoordinateCalculator.UNIT_HEIGHT) - coordinateCalc.resize(2*b));
		g.setColor(color.darker().darker());
		g.drawOval(coordinateCalc.getX(mapUnit.getPos()) + coordinateCalc.resize(b), 
				   coordinateCalc.getY(mapUnit.getPos()) + coordinateCalc.resize(b), 
				   coordinateCalc.resize(CoordinateCalculator.UNIT_WIDTH) - coordinateCalc.resize(2*b), 
				   coordinateCalc.resize(CoordinateCalculator.UNIT_HEIGHT) - coordinateCalc.resize(2*b));
		//hp
		int left_border = 10;
		int right_border = 4;
		int bottom_border = 6;
		// bordo all'interno
		int intBorder = 1;
		//altezza bordo
		int height = 4;
		//hp
		int hp = getPlayer().getActualStat().getStat(Statistiche.HP);
		int maxHP = getPlayer().getMaxStat(Statistiche.HP);
		drawStat(g, Color.green, (float)hp/maxHP, left_border, right_border, bottom_border, intBorder, height);
		//mp
		int mp = getPlayer().getActualStat().getStat(Statistiche.MP);
		int maxMP = getPlayer().getMaxStat(Statistiche.MP);
		drawStat(g, Color.yellow, (float)mp/maxMP, left_border, right_border+4, bottom_border-height, intBorder, height);
	}
	
	protected void drawStat(Graphics2D g, Color color, float value, int left_border, int right_border, int bottom_border, int intBorder, int height){
		g.setColor(Color.black);
		g.fillRect(coordinateCalc.getX(mapUnit.getPos())+coordinateCalc.resize(left_border), 
				   coordinateCalc.getY(mapUnit.getPos())+coordinateCalc.resize(CoordinateCalculator.UNIT_HEIGHT-bottom_border-height),
				   coordinateCalc.resize(CoordinateCalculator.UNIT_WIDTH)-coordinateCalc.resize(left_border+right_border), 
				   coordinateCalc.resize(height));
		g.setColor(color);
		int width = coordinateCalc.resize(CoordinateCalculator.UNIT_WIDTH)-coordinateCalc.resize(left_border+right_border+2*intBorder);
		g.fillRect(coordinateCalc.getX(mapUnit.getPos()) + coordinateCalc.resize(left_border + intBorder), 
				   coordinateCalc.getY(mapUnit.getPos())+coordinateCalc.resize(CoordinateCalculator.UNIT_HEIGHT - height -bottom_border + intBorder),
				   Math.round((float)value * width), 
				   coordinateCalc.resize(height - 2*intBorder));
	}

	public BattleMapUnit getMapUnit() {
		return mapUnit;
	}
	public void setMapUnit(BattleMapUnit mapUnit) {
		this.mapUnit = mapUnit;
	}
	public Color getColor() {
		return color;
	}
	public void setColor(Color color) {
		this.color = color;
	}
	public CoordinateCalculator getCoordinateCalc() {
		return coordinateCalc;
	}
	public void setCoordinateCalc(CoordinateCalculator coordinateCalc) {
		this.coordinateCalc = coordinateCalc;
	}
	public DefaultPlayer getPlayer() {
		return player;
	}
	public void setPlayer(DefaultPlayer player) {
		this.player = player;
	}
	
}
